﻿package classes.utils{
	import flash.display.Stage;
	import flash.events.KeyboardEvent;
	
	public class PopKeys{
		static private var aState:Array = new Array();
			
		static public function initStage(stg:Stage):void{
			stg.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,false,0,true);
			stg.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler,false,0,true);			
		}
		
		static public function clearState(stg:Stage):void{
			stg.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
			stg.removeEventListener(KeyboardEvent.KEY_UP,keyUpHandler);
			aState = [];
		}
		
		static public function isDown(code:uint):Boolean{
			return aState[code] == true;
		}
		static private function keyDownHandler(e:KeyboardEvent):void{
			aState[e.keyCode] = true;
		}
		static private function keyUpHandler(e:KeyboardEvent):void{
			aState[e.keyCode] = false;
		}		
	}
}